import sysConfig from "@/config";

export default {
	methods: {
		openFileOnLine(extName, netDiskId, role, path) {
			if (this.$TOOL.data.get("OFFICE_TYPE") == '0') {
				if (sysConfig.DOC_FILE.includes(extName)) {
					POBrowser.openWindowModeless(this.$TOOL.data.get("ATTACH_HOST")  + '/office/openword?netDiskId=' + netDiskId + '&path=' + encodeURIComponent(path) + '&extName=' + extName + '&openModeType=' + role, 'width=1200px;height=800px;scroll=no;');
				} else if (sysConfig.EXCEL_FILE.includes(extName)) {
					POBrowser.openWindowModeless(this.$TOOL.data.get("ATTACH_HOST")  + '/office/openexcel?netDiskId=' + netDiskId + '&path=' + encodeURIComponent(path) + '&extName=' + extName + '&openModeType=' + role, 'width=1200px;height=800px;scroll=no;');
				} else if (sysConfig.PPT_FILE.includes(extName)) {
					POBrowser.openWindowModeless(this.$TOOL.data.get("ATTACH_HOST")  + '/office/openppt?netDiskId=' + netDiskId + '&path=' + encodeURIComponent(path) + '&extName=' + extName + '&openModeType=' + role, 'width=1200px;height=800px;scroll=no;');
				} else if (sysConfig.PDF_FILE.includes(extName)) {
					POBrowser.openWindowModeless(this.$TOOL.data.get("ATTACH_HOST")  + '/office/openpdf?netDiskId=' + netDiskId + '&path=' + encodeURIComponent(path) + '&extName=' + extName + '&openModeType=' + role, 'width=1200px;height=800px;scroll=no;');
				} else if (sysConfig.IMG_FILE.includes(extName)) {
					const image = new Image()
					image.src = sysConfig.API_URL+'/get/file/downNetDiskFile?netDiskId=' + netDiskId + "&fileName=" + encodeURIComponent(path)+"&ddtab=true"
						image.onload = () => {
							image.style.margin = "0 auto"
							image.style.display = "block"
							const newWin = window.open("", "_blank")
							newWin.document.write(image.outerHTML)
						}
				}
			} else if (this.$TOOL.data.get("OFFICE_TYPE") == '2') {
				if(sysConfig.DOC_FILE.includes(extName))
				{
					window.open(this.$TOOL.data.get("ATTACH_HOST")+'/office/wps/openword?netDiskId=' + netDiskId + '&path=' + encodeURIComponent(path) + '&extName=' + extName + '&openModeType=' + role+'&token='+this.$TOOL.cookie.get("TOKEN")+"&ddtab=true");
				}else if(sysConfig.EXCEL_FILE.includes(extName))
				{
					window.open(this.$TOOL.data.get("ATTACH_HOST")+'/office/wps/openexcel?netDiskId=' + netDiskId + '&path=' + encodeURIComponent(path) + '&extName=' + extName + '&openModeType=' + role+'&token='+this.$TOOL.cookie.get("TOKEN")+"&ddtab=true");
				}else if(sysConfig.PPT_FILE.includes(extName))
				{
					window.open(this.$TOOL.data.get("ATTACH_HOST")+'/office/wps/openppt?netDiskId=' + netDiskId + '&path=' + encodeURIComponent(path) + '&extName=' + extName + '&openModeType=' + role+'&token='+this.$TOOL.cookie.get("TOKEN")+"&ddtab=true");
				}else if(sysConfig.PDF_FILE.includes(extName))
				{
					if(extName=='.ofd')
					{
						this.$nextTick(() => {
							window.open('/#/file/preview/ofd?netDiskId=' + netDiskId + "&extName=" + extName + "&isNetDisk=true&attachId=" +encodeURIComponent(path)+"&ddtab=true", "_blank");
						})
					}else{
						this.$nextTick(() => {
							window.open('/#/file/preview/pdf?netDiskId=' + netDiskId + "&extName=" + extName + "&isNetDisk=true&attachId=" +encodeURIComponent(path)+"&ddtab=true", "_blank");
						})
					}
				}else if (sysConfig.IMG_FILE.includes(extName)) {
					const image = new Image()
					image.src = sysConfig.API_URL+'/get/file/downNetDiskFile?netDiskId=' + netDiskId + "&fileName=" + encodeURIComponent(path)+"&ddtab=true"
						image.onload = () => {
							image.style.margin = "0 auto"
							image.style.display = "block"
							const newWin = window.open("", "_blank")
							newWin.document.write(image.outerHTML)
						}
				}
			}else if (this.$TOOL.data.get("OFFICE_TYPE") == '3') {
				if(sysConfig.DOC_FILE.includes(extName)||sysConfig.EXCEL_FILE.includes(extName)||sysConfig.PPT_FILE.includes(extName))
				{
					window.open(this.$TOOL.data.get("ATTACH_HOST")+'/v3/weboffice/index?attachId='+encodeURIComponent(path)+'&netDiskId=' + netDiskId+'&extName='+extName+'&openModeType=' + role+'&isNetDisk=1&token='+this.$TOOL.cookie.get("TOKEN")+"&ddtab=true");
				}else if(sysConfig.PDF_FILE.includes(extName))
				{
					this.openPdfFile(extName, netDiskId, role, path)
				}else if (sysConfig.IMG_FILE.includes(extName)) {
					const image = new Image()
					image.src = sysConfig.API_URL+'/get/file/downNetDiskFile?netDiskId=' + netDiskId + "&fileName=" + encodeURIComponent(path)+"&ddtab=true"
					image.onload = () => {
						image.style.margin = "0 auto"
						image.style.display = "block"
						const newWin = window.open("", "_blank")
						newWin.document.write(image.outerHTML)
					}
				}
			}
		},
		openPdfFile(extName, netDiskId, role, path) {
			if (this.$TOOL.data.get("OFD_TYPE") === '0') {
				if(extName=='.ofd')
				{
					this.$nextTick(() => {
						window.open('/#/file/preview/ofd?attachId=' + path + "&extName=" + extName+ "&netDiskId=" + netDiskId+ "&isNetDisk=true"+"&ddtab=true", "_blank");
					})
				}else {
					this.$nextTick(() => {
						window.open('/#/file/preview/pdf?attachId=' + path + "&extName=" + extName+ "&netDiskId=" + netDiskId+ "&isNetDisk=true"+"&ddtab=true", "_blank");
					})
				}
			} else if (this.$TOOL.data.get("OFD_TYPE") === '1') {
				this.$nextTick(() => {
					window.open(this.$TOOL.data.get("ATTACH_HOST") + '/office/ofd/openfxofd?attachId=' + path + "&extName=" + extName+ "&netDiskId=" + netDiskId+ "&isNetDisk=true&openModeType="+role+"&ddtab=true", "_blank");
				})
			} else if (this.$TOOL.data.get("OFD_TYPE") === '2') {
				this.$nextTick(() => {
					window.open(this.$TOOL.data.get("ATTACH_HOST") + '/office/ofd/openswofd?attachId=' + path + "&extName=" + extName+ "&netDiskId=" + netDiskId+ "&isNetDisk=true&openModeType="+role+"&ddtab=true", "_blank");
				})
			}
		},
	}
}
